<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单管理接口测试</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container {
            margin-top: 30px;
        }

        .card {
            margin-bottom: 20px;
        }

        .response-area {
            background-color: #f8f9fa;
            padding: 10px;
            border-radius: 5px;
            min-height: 100px;
            max-height: 300px;
            overflow-y: auto;
        }
    </style>
</head>

<body>
    <div class="container">
        <h2 class="mb-4">订单管理接口测试</h2>

        <!-- 订单基础信息 -->
        <div class="card">
            <div class="card-header">
                <h5>订单基础信息</h5>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <button class="btn btn-primary" onclick="getOrderDetail()">获取订单详情</button>
                    <input type="text" id="orderNo" class="form-control d-inline-block w-25" placeholder="订单编号">
                </div>
                <div class="mb-3">
                    <button class="btn btn-success" onclick="createOrder()">创建订单</button>
                    <button class="btn btn-warning" onclick="updateOrder()">修改订单</button>
                    <button class="btn btn-danger" onclick="cancelOrder()">取消订单</button>
                </div>
            </div>
        </div>

        <!-- 订单支付信息 -->
        <div class="card">
            <div class="card-header">
                <h5>订单支付信息</h5>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <button class="btn btn-primary" onclick="getOrderPayment()">获取支付信息</button>
                    <button class="btn btn-success" onclick="createPayment()">创建支付</button>
                    <button class="btn btn-info" onclick="queryPaymentStatus()">查询支付状态</button>
                </div>
            </div>
        </div>

        <!-- 订单优惠券信息 -->
        <div class="card">
            <div class="card-header">
                <h5>订单优惠券信息</h5>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <button class="btn btn-primary" onclick="getOrderCoupon()">获取优惠券信息</button>
                    <button class="btn btn-success" onclick="applyCoupon()">使用优惠券</button>
                    <button class="btn btn-warning" onclick="removeCoupon()">移除优惠券</button>
                </div>
            </div>
        </div>

        <!-- 订单评价信息 -->
        <div class="card">
            <div class="card-header">
                <h5>订单评价信息</h5>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <button class="btn btn-primary" onclick="getOrderReview()">获取评价信息</button>
                    <button class="btn btn-success" onclick="submitReview()">提交评价</button>
                    <button class="btn btn-warning" onclick="updateReview()">修改评价</button>
                </div>
            </div>
        </div>

        <!-- 订单退款信息 -->
        <div class="card">
            <div class="card-header">
                <h5>订单退款信息</h5>
            </div>
            <div class="card-body">
                <div class="mb-3">
                    <button class="btn btn-primary" onclick="getOrderRefund()">获取退款信息</button>
                    <button class="btn btn-success" onclick="applyRefund()">申请退款</button>
                    <button class="btn btn-warning" onclick="updateRefund()">更新退款状态</button>
                </div>
            </div>
        </div>

        <!-- 响应结果 -->
        <div class="card">
            <div class="card-header">
                <h5>响应结果</h5>
            </div>
            <div class="card-body">
                <pre id="response" class="response-area"></pre>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
        // 基础URL
        const baseUrl = '/order';

        // 显示响应结果
        function showResponse (data) {
            $('#response').text(JSON.stringify(data, null, 2));
        }

        // 订单基础信息接口
        function getOrderDetail () {
            const orderNo = $('#orderNo').val();
            $.get(`${baseUrl}/${orderNo}`, function (data) {
                showResponse(data);
            });
        }

        function createOrder () {
            const orderData = {
                userId: 1,
                deviceId: 1,
                totalAmount: 100.00,
                actualAmount: 100.00,
                discountAmount: 0.00,
                payType: 1,
                status: 0
            };
            $.ajax({
                url: baseUrl,
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(orderData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        function updateOrder () {
            const orderNo = $('#orderNo').val();
            const orderData = {
                orderNo: orderNo,
                status: 1,
                remark: "更新订单信息"
            };
            $.ajax({
                url: baseUrl,
                type: 'PUT',
                contentType: 'application/json',
                data: JSON.stringify(orderData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        function cancelOrder () {
            const orderNo = $('#orderNo').val();
            const cancelData = {
                orderNo: orderNo,
                cancelReason: "用户取消订单"
            };
            $.ajax({
                url: `${baseUrl}/cancel`,
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(cancelData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        // 订单支付信息接口
        function getOrderPayment () {
            const orderNo = $('#orderNo').val();
            $.get(`${baseUrl}/payment/${orderNo}`, function (data) {
                showResponse(data);
            });
        }

        function createPayment () {
            const orderNo = $('#orderNo').val();
            const paymentData = {
                orderNo: orderNo,
                paymentType: 1,
                paymentAmount: 100.00
            };
            $.ajax({
                url: `${baseUrl}/payment`,
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(paymentData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        function queryPaymentStatus () {
            const orderNo = $('#orderNo').val();
            $.get(`${baseUrl}/payment/status/${orderNo}`, function (data) {
                showResponse(data);
            });
        }

        // 订单优惠券信息接口
        function getOrderCoupon () {
            const orderNo = $('#orderNo').val();
            $.get(`${baseUrl}/coupon/${orderNo}`, function (data) {
                showResponse(data);
            });
        }

        function applyCoupon () {
            const orderNo = $('#orderNo').val();
            const couponData = {
                orderNo: orderNo,
                couponCode: "TEST123",
                couponType: 1
            };
            $.ajax({
                url: `${baseUrl}/coupon/apply`,
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(couponData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        function removeCoupon () {
            const orderNo = $('#orderNo').val();
            $.ajax({
                url: `${baseUrl}/coupon/remove/${orderNo}`,
                type: 'POST',
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        // 订单评价信息接口
        function getOrderReview () {
            const orderNo = $('#orderNo').val();
            $.get(`${baseUrl}/review/${orderNo}`, function (data) {
                showResponse(data);
            });
        }

        function submitReview () {
            const orderNo = $('#orderNo').val();
            const reviewData = {
                orderNo: orderNo,
                rating: 5,
                content: "商品质量很好，服务态度也很好",
                images: "image1.jpg,image2.jpg"
            };
            $.ajax({
                url: `${baseUrl}/review`,
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(reviewData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        function updateReview () {
            const orderNo = $('#orderNo').val();
            const reviewData = {
                orderNo: orderNo,
                rating: 4,
                content: "修改后的评价内容",
                images: "image1.jpg"
            };
            $.ajax({
                url: `${baseUrl}/review`,
                type: 'PUT',
                contentType: 'application/json',
                data: JSON.stringify(reviewData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        // 订单退款信息接口
        function getOrderRefund () {
            const orderNo = $('#orderNo').val();
            $.get(`${baseUrl}/refund/${orderNo}`, function (data) {
                showResponse(data);
            });
        }

        function applyRefund () {
            const orderNo = $('#orderNo').val();
            const refundData = {
                orderNo: orderNo,
                refundAmount: 100.00,
                refundType: 1,
                reason: "商品质量问题"
            };
            $.ajax({
                url: `${baseUrl}/refund/apply`,
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(refundData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }

        function updateRefund () {
            const orderNo = $('#orderNo').val();
            const refundData = {
                orderNo: orderNo,
                status: 2,
                handleResult: "退款已处理"
            };
            $.ajax({
                url: `${baseUrl}/refund/update`,
                type: 'PUT',
                contentType: 'application/json',
                data: JSON.stringify(refundData),
                success: function (data) {
                    showResponse(data);
                }
            });
        }
    </script>
</body>

</html>